import React, {forwardRef} from "react";

export default function ForwardApp() {
    const inputRef = React.useRef(null);

    return <div>
        <button onClick={() => {
            inputRef.current.focus();
            inputRef.current.value = "";
        }}>获取焦点</button>
        <Child ref={inputRef} />
    </div>;
}

const Child = forwardRef((props, ref) => {
    return <div>
        <input ref={ref} defaultValue="222"/>
    </div>
})